<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // JSON.stringify() 将对象转为JSON格式的字符串
        // JSON.parse() 将JSON格式的字符串转为对象
        const obj = {
            name: '东东',
            age: 28,
            hobby: ['dance', 'sing', 'rap'],
            family: {
                name: '练练',
                age: 28,
                son: {
                    name: 'dd',
                    age: 10
                }
            },
            data: [{
                salary: 2000,
                price: 1000
            }],
            test1: function () { },
            test2: undefined,
            test3: Symbol('id'),
            test4: NaN,
            test5: Infinity,
            test6: new RegExp(/浅/, 'g'),
            test7: new Date()
        }
        const res = JSON.parse(JSON.stringify(obj))
        // console.log(res)
        res.hobby[0] = 'run'
        console.log(obj)
        console.log(res)

        // 缺陷：
        // 1. 如果拷贝对象的属性是function，undefined，Symbol，这个键值对会丢失
        // 2. 如果是NaN，Infinity， 属性值会变为null
        // 3. 如果是正则，变为空对象
        // 4. 如果是new Date(), 会变为字符串
    </script>
</body>

</html>